#include <iostream>
#include <mpi.h>

#ifndef NDEBUG
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#endif //NDEBUG

#include "Types.h"
#include "NavierStokesSolver.h"
#include "CFDProblem.h"
#include "CartesianTopology.h"
#include "Communicator.h"


#include "CFDProblemFactory.h"
#include "NSEWriter.h"
#include "VTKWriter.h"



/// set all the matrix with random vals between 0 and 20
inline void SetRandom(nsesolver::Matrixd &m)
{
    utils::SRand(1);
    
    for (int i = 0; i < m.size(); i++) {
        m[i] = utils::Rand()*20.0;
    }
}

/// a defaul inflow
inline double inflow(double useless)
{
    NSE_SOLVER_UNUSED(useless);
    return 1.0;
}

/// entry point
int main (int argc, char ** argv) {
	using namespace nsesolver;
    using namespace nsesolver::mpi;
    
    MPI_Init(&argc, &argv);
    
#ifdef CIPPO
//#ifndef NDEBUG    
    CppUnit::TextUi::TestRunner runner;
    CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
    
    
    runner.addTest( registry.makeTest() );
    
    return runner.run();
    
#else
    
    const double gx = 0, gy = 0;
    const double omega = 1.7;
    const double t0 = 0, tEnd = 10, Re = 1000;
 
    const int imax = 60; 
    const int jmax = 60;     
    CartesianTopology cart(2);
    
    const std::string path="/Users/patrick/Desktop/Master/2nd_semester/Computational_Fluid_Dynamics/nsesolver/obstacles/_CFD_Course__DrivenCavityGeometry.e";
   // const std::string path="/Users/teseo/Documents/scuola/2011SS/fluids/nsesolver/obstacles/_CFD_Course__DrivenCavityGeometry.e";
    Reference< CFDProblem > problem(CFDProblemFactory::createProblem(path,  cart, imax, jmax));
    problem->getBoundaryConditions().setUInflowOutflow(inflow);

    NavierStokesSolver solver;
    //solver.setWriter(new VTKWriter("/Users/teseo/Desktop/res", cart));
    solver.setWriter(new VTKWriter("/Users/patrick/Desktop/results", cart));

    
    
    solver.solve(*problem, t0, tEnd, omega, Re, gx, gy);

    return MPI_Finalize();
    
#endif //NDEBUG
    
    
}
